
#include"head.h"


//执行指令
int execute_choose(int choose,struct login_status* stat,int* status,struct client_info* info,int socket_fd)
{
    switch(choose)
    {
    case 0:
        *status=1;
        break;
    case 1:
        printf("请登录:\n");

        //登录逻辑
        printf("请输入账号:");
        scanf("%s",stat->name);

        printf("请输入密码:");
        scanf("%s",stat->password);

        //合并初始地址
        sscanf(stat->name,"/%s",stat->path);

        info->command=LOGIN;
        
        //拼接protocol
        joint_stdin(stat,info);

        //验证账号
        send(socket_fd,info,sizeof(info),MSG_NOSIGNAL);
        //todo验证账号的正确并接受返回值修改本地结构体参数

        stat->login=true;
        break;

    case 2:
        printf("请注册\n");

        //注册
        printf("请输入账号，小于8位");
        char name[10];
        sscanf(STDIN_FILENO,"%s",name);
        printf("请输入密码,小于18位");
        char password[20];
        sscanf(STDIN_FILENO,"%s",password);
        info->command=REGIST;
        //注册完成之后向服务器发送完成当前注册
        //判断用户名是否重复
        break;

    default:
        printf("你的输入有问题请检查后重新输入\n");
        break;
    }
    return 0;
}

//分割命令
int depart_command(struct client_info* info , char * msg)
{
    char* command=strtok(msg," ");
    //命令匹配
    ensure_command(command,info);
    
    if(info->command!=ERROR)
    {
    //跳过空白
    char* param=strtok(NULL," ");
    
    //把参数线拷贝到info
    memcpy(info->protocol,param,strlen(param));
    }
    return 0;
}




